﻿/// <reference path="JSintellisense/jquery-1.3.2-vsdoc2.js" />

/*
    历史地址js
    用户历史地址，点过的就保存，保存最新3个
    先进先出
*/


var address =
{
    time: "",
    url: "",
    lat: "",
    lng: "",
    label: "",
    door: ""
};

var addresskey = ["f_address", "t_address"];

var FromAddress = {
    key: "f_address",
    add: function (address)
    {
        var historyaddress = utils.getParam(FromAddress.key);
        if (historyaddress == null || historyaddress == "") {
            var jsonstr = { "productlist": [{ "url": address.url, "label": address.label, "lat": address.lat, "lng": address.lng, "time": address.time, "door": address.door }] };
            utils.setParam(FromAddress.key, "'" + JSON.stringify(jsonstr));
        }
        else {
            var jsonstr = JSON.parse(historyaddress.substr(1, historyaddress.length));
            var productlist = jsonstr.productlist;
            var result = false;
            for (var i in productlist) {
                if (productlist[i].lat == address.lat && productlist[i].lng == address.lng) {
                    result = true;
                }
            }
            if (!result) {
                productlist.push({ "url": address.url, "label": address.label, "lat": address.lat, "lng": address.lng, "time": address.time, "door": address.door });
            }

            var last3address = new Array();
            var j = 0;
         
            for (var i = productlist.length - 1, j = 0; i >= 0 && j < 3; i--, j++) {

                if (parseFloat(productlist[i].lat) < 60) {
                    last3address.push(productlist[i])
                }


            }
            jsonstr.productlist = last3address;

            utils.setParam(FromAddress.key, "'" + JSON.stringify(jsonstr));
        }
    },
    //获取地址
    getproductlist: function () {
        var historyaddress = utils.getParam(FromAddress.key);
        //debugger;
        if (historyaddress == null || historyaddress == "" || historyaddress == "null" || historyaddress == "0") {
            return [];
        }
        var jsonstr = JSON.parse(historyaddress.substr(1, historyaddress.length));
        var productlist = jsonstr.productlist;
        return productlist;
    },
    //删除所有地址
    deleteallproduct: function () {
        utils.setParam(FromAddress.key, "");
    }
};
